<template>
  <div class="audit_form" v-drag>
    <div class="title">
      <span>审核信息</span>
      <div class="off">
        <off-btn @off="offAudit"></off-btn>
      </div>
    </div>
    <div class="form" @mousemove.stop @mousedown.stop>
      <span>标题：{{formObj.title}}</span>
      <span>标签：{{formObj.tag}}</span>
      <span>上传时间：{{timer(formObj.time)}}</span>
      <span>上传用户：<a href="JavaScript:;">{{formObj.username}}</a></span>
      <span>审核是否通过：<input type="checkbox" v-model="isPass"></span>
      <span v-if="isPass">分类：
        <select name="classify" id="classify" v-model="classify">
          <option value="">请选择</option>
          <option v-for="(item,index) in $store.state.articleClassify" :key="index" :value="item">{{item}}</option>
        </select>
      </span>
      <span v-else>
        <textarea v-model="cause" name="cause" id="cause" maxlength="50" placeholder="备注原因"></textarea>
      </span>
      <span @click="submitAudit" class="btn">提交</span>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import tool from '../../../../assets/js/tool';
import offBtn from '../../../info/offBtn.vue'
export default {
  name: 'Auditform',

  data() {
    return {
      offIcon:'#icon-guanbi', // 关闭图标
      isPass: '', // 是否通过
      classify: '', // 文章分类
      cause:'' // 未通过原因
    };
  },

  props: {
    formObj: Object
  },

  computed: {
    timer(){
      return (time) => tool.GetTimer(time)
    }
  },

  mounted() {
    
  },

  methods: {
    // 关闭审核
    offAudit(){
      this.$emit('offAudit')
    },
    // 提交审核
    submitAudit(){
      if(this.isPass && this.classify.trim()==''){
        this.showHint({title:'文章未分类',isFlag:false})
        return
      }else if(!this.isPass && this.cause.trim()==''){
        this.showHint({title:'请说明原因',isFlag:false})
      }else{
        this.$api.submitAudit({
          id: this.formObj.articleid,
          classify: this.classify,
          cause: this.cause
        }).then(() => {
          this.showHint({title:'提交成功!',isFlag:true})
          this.$emit('submitAudit',this.formObj.articleid)
          this.offAudit()
        })
      }
    },
    ...mapActions(['showHint'])
  },
  components: {
    offBtn
  }
};
</script>

<style scoped>
.audit_form{
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  width: 30%;
  background-color: white;
  box-shadow: 0 0 5px 2px rgb(190, 190, 190);
  border-radius: 10px;
}
.audit_form .title{
  width: 100%;
  height: 40px;
  line-height: 40px;
  text-align: center;
  color: gray;
  letter-spacing: 1rem;
  position: relative;
  background-image: linear-gradient(to top,rgba(255, 187, 0, 0.2), rgba(255, 187, 0, 0.5),rgba(255, 187, 0, 1));
}
.audit_form .title .off{
  position: absolute;
  top: 0;
  right: 10px;
  font-size: 1.5rem;
  cursor: pointer;
}
.form{
  display: flex;
  flex-direction: column;
  font-size: .8rem;
  padding: 20px;
}
.form span{
  margin: 10px 0;
}
.form input{
  vertical-align: text-bottom;
}
.form span textarea{
  outline: none;
  padding: 4px;
  width: 100%;
  height: 60px;
  border: 1px solid gray;
}
.form .btn{
  padding: 10px;
  margin: 0;
  border: 1px solid gray;
  background-color: green;
  opacity: .7;
  color: white;
  cursor: pointer;
  text-align: center;
}
#classify{
  border: 1px solid gray;
  outline: none;
}
.form .btn:hover{
  opacity: 1;
}
</style>